package com.spt.ws.services;


import org.apache.logging.log4j.LogManager;  
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.spt.ws.dao.IDaoService;


public class CommFjjServiceImpl implements ICommFjjService{
	private static Logger log = LogManager.getLogger("com.spt.ws.ws");
	@Autowired
	private IDaoService daoService;
	
	@Override
	public String getYJGK(String parm) {
		log.info("receive msg is :" + parm);
		StringBuffer sb = new StringBuffer("#MSG::");
		String lines = this.getParm(parm);
		if(lines==null || "".equals(lines)){
			sb.append("-1::no rows::#END");
			return sb.toString();
		}
		try {
			daoService.getYJGK(lines);
			sb.append("0::success::#END");
		} catch (Exception e) {
			sb.append("-1::").append(e.getMessage()).append(" all rollbacked::#END");
			e.printStackTrace();
		}
		log.info("return msg is :" + sb.toString());
		return sb.toString();
	}
	
	
	private String getParm(String s){
		if("#HEAD::#END".equalsIgnoreCase(s)) return null;
		if (s.startsWith("#HEAD") && s.endsWith("#END")){
			String a = s.replace("#HEAD", "");
			a = a.replace("#END", "");
			return a;
		}else{
			return null;
		}
		
	}


	@Override
	public String getLXGK(String parm) {
		log.info("getLXGK receive msg is :" + parm);
		StringBuffer sb = new StringBuffer("#MSG::");
		String lines = this.getParm(parm);
		if(lines==null || "".equals(lines)){
			sb.append("-1::no rows or error rows::#END");
			return sb.toString();
		}
		try {
			daoService.getLXGK(lines);
			sb.append("0::success::#END");
		} catch (Exception e) {
			sb.append("-1::").append(e.getMessage()).append(" all rollbacked::#END");
			e.printStackTrace();
		}
		log.info("return msg is :" + sb.toString());
		return sb.toString();
	}


	@Override
	public String getWLGKQH(String parm) {
		log.info("getWLGKQH receive msg is :" + parm);
		StringBuffer sb = new StringBuffer("#MSG::");
		String lines = this.getParm(parm);
		if(lines==null || "".equals(lines)){
			sb.append("-1::no rows or error rows::#END");
			return sb.toString();
		}
		try {
			daoService.getWLGKQH(lines);
			sb.append("0::success::#END");
		} catch (Exception e) {
			sb.append("-1::").append(e.getMessage()).append(" all rollbacked::#END");
			e.printStackTrace();
		}
		log.info("return msg is :" + sb.toString());
		return sb.toString();
	}


	@Override
	public String getCZYB(String parm) {
		log.info("getCZYB receive msg is :" + parm);
		StringBuffer sb = new StringBuffer("#MSG::");
		String lines = this.getParm(parm);
		if(lines==null || "".equals(lines)){
			sb.append("-1::no rows or error rows::#END");
			return sb.toString();
		}
		try {
			daoService.getCZYB(lines);
			sb.append("0::success::#END");
		} catch (Exception e) {
			sb.append("-1::").append(e.getMessage()).append(" all rollbacked::#END");
			e.printStackTrace();
		}
		log.info("return msg is :" + sb.toString());
		return sb.toString();
	}


	@Override
	public String getJFFA(String parm) {
		log.info("getJFFA receive msg is :" + parm);
		StringBuffer sb = new StringBuffer("#MSG::");
		String lines = this.getParm(parm);
		if(lines==null || "".equals(lines)){
			sb.append("-1::no rows or error rows::#END");
			return sb.toString();
		}
		try {
			daoService.getJFFA(lines);
			sb.append("0::success::#END");
		} catch (Exception e) {
			sb.append("-1::").append(e.getMessage()).append(" all rollbacked::#END");
			e.printStackTrace();
		}
		log.info("return msg is :" + sb.toString());
		return sb.toString();
	}


	@Override
	public String getGKSG(String parm) {
		log.info("getGKSG receive msg is :" + parm);
		StringBuffer sb = new StringBuffer("#MSG::");
		String lines = this.getParm(parm);
		if(lines==null || "".equals(lines)){
			sb.append("-1::no rows or error rows::#END");
			return sb.toString();
		}
		try {
			daoService.getGKSG(lines);
			sb.append("0::success::#END");
		} catch (Exception e) {
			sb.append("-1::").append(e.getMessage()).append(" all rollbacked::#END");
			e.printStackTrace();
		}
		log.info("return msg is :" + sb.toString());
		return sb.toString();
	}


	@Override
	public String getDQFA(String parm) {
		log.info("getDQFA receive msg is :" + parm);
		StringBuffer sb = new StringBuffer("#MSG::");
		String lines = this.getParm(parm);
		if(lines==null || "".equals(lines)){
			sb.append("-1::no rows or error rows::#END");
			return sb.toString();
		}
		try {
			daoService.getDQFA(lines);
			sb.append("0::success::#END");
		} catch (Exception e) {
			sb.append("-1::").append(e.getMessage()).append(" all rollbacked::#END");
			e.printStackTrace();
		}
		log.info("return msg is :" + sb.toString());
		return sb.toString();
	}


	@Override
	public String getGKSX(String parm) {
		log.info("getGKSX receive msg is :" + parm);
		StringBuffer sb = new StringBuffer("#MSG::");
		String lines = this.getParm(parm);
		if(lines==null || "".equals(lines)){
			sb.append("-1::no rows or error rows::#END");
			return sb.toString();
		}
		try {
			daoService.getGKSX(lines);
			sb.append("0::success::#END");
		} catch (Exception e) {
			sb.append("-1::").append(e.getMessage()).append(" all rollbacked::#END");
			e.printStackTrace();
		}
		log.info("return msg is :" + sb.toString());
		return sb.toString();
	}


	@Override
	public String getZXJDS(String parm) {
		log.info("getZXJDS receive msg is :" + parm);
		StringBuffer sb = new StringBuffer("#MSG::");
		String lines = this.getParm(parm);
		if(lines==null || "".equals(lines)){
			sb.append("-1::no rows or error rows::#END");
			return sb.toString();
		}
		try {
			daoService.getZXJDS(lines);
			sb.append("0::success::#END");
		} catch (Exception e) {
			sb.append("-1::").append(e.getMessage()).append(" all rollbacked::#END");
			e.printStackTrace();
		}
		log.info("return msg is :" + sb.toString());
		return sb.toString();
	}


	@Override
	public String getDSXS(String parm) {
		log.info("getDSXS receive msg is :" + parm);
		StringBuffer sb = new StringBuffer("#MSG::");
		String lines = this.getParm(parm);
		if(lines==null || "".equals(lines)){
			sb.append("-1::no rows or error rows::#END");
			return sb.toString();
		}
		try {
			daoService.getDSXS(lines);
			sb.append("0::success::#END");
		} catch (Exception e) {
			sb.append("-1::").append(e.getMessage()).append(" all rollbacked::#END");
			e.printStackTrace();
		}
		log.info("return msg is :" + sb.toString());
		return sb.toString();
	}


	@Override
	public String getXSTD(String parm) {
		log.info("getXSTD receive msg is :" + parm);
		StringBuffer sb = new StringBuffer("#MSG::");
		String lines = this.getParm(parm);
		if(lines==null || "".equals(lines)){
			sb.append("-1::no rows or error rows::#END");
			return sb.toString();
		}
		try {
			daoService.getXSTD(lines);
			sb.append("0::success::#END");
		} catch (Exception e) {
			sb.append("-1::").append(e.getMessage()).append(" all rollbacked::#END");
			e.printStackTrace();
		}
		log.info("return msg is :" + sb.toString());
		return sb.toString();
	}


	@Override
	public String getTTDYB(String parm) {
		log.info("getTTDYB receive msg is :" + parm);
		StringBuffer sb = new StringBuffer("#MSG::");
		String lines = this.getParm(parm);
		if(lines==null || "".equals(lines)){
			sb.append("-1::no rows or error rows::#END");
			return sb.toString();
		}
		try {
			daoService.getTTDYB(lines);
			sb.append("0::success::#END");
		} catch (Exception e) {
			sb.append("-1::").append(e.getMessage()).append(" all rollbacked::#END");
			e.printStackTrace();
		}
		log.info("return msg is :" + sb.toString());
		return sb.toString();
	}


	@Override
	public String getXSYB(String parm) {
		log.info("getXSYB receive msg is :" + parm);
		StringBuffer sb = new StringBuffer("#MSG::");
		String lines = this.getParm(parm);
		if(lines==null || "".equals(lines)){
			sb.append("-1::no rows or error rows::#END");
			return sb.toString();
		}
		try {
			daoService.getXSYB(lines);
			sb.append("0::success::#END");
		} catch (Exception e) {
			sb.append("-1::").append(e.getMessage()).append(" all rollbacked::#END");
			e.printStackTrace();
		}
		log.info("return msg is :" + sb.toString());
		return sb.toString();
	}


	@Override
	public String getTMYJZL(String parm) {
		log.info("getTMYJZL receive msg is :" + parm);
		StringBuffer sb = new StringBuffer("#MSG::");
		String lines = this.getParm(parm);
		if(lines==null || "".equals(lines)){
			sb.append("-1::no rows or error rows::#END");
			return sb.toString();
		}
		try {
			daoService.getTMYJZL(lines);
			sb.append("0::success::#END");
		} catch (Exception e) {
			sb.append("-1::").append(e.getMessage()).append(" all rollbacked::#END");
			e.printStackTrace();
		}
		log.info("return msg is :" + sb.toString());
		return sb.toString();
	}


	@Override
	public String getTYJZLDYGX(String parm) {
		log.info("getTYJZLDYGX receive msg is :" + parm);
		StringBuffer sb = new StringBuffer("#MSG::");
		String lines = this.getParm(parm);
		if(lines==null || "".equals(lines)){
			sb.append("-1::no rows or error rows::#END");
			log.info("getTYJZLDYGX result is :" + sb.toString());
			return sb.toString();
		}
		try {
			daoService.getTYJZLDYGX(lines);
			sb.append("0::success::#END");
		} catch (Exception e) {
			sb.append("-1::").append(e.getMessage()).append(" all rollbacked::#END");
		}
		log.info("return msg is :" + sb.toString());
		return sb.toString();
	}
	
	@Override
	public String getKCFA(String parm) {
		log.info("getKCFA receive msg is :" + parm);
		StringBuffer sb = new StringBuffer("#MSG::");
		String lines = this.getParm(parm);
		if(lines==null || "".equals(lines)){
			sb.append("-1::no rows or error rows::#END");
			log.info("getKCFA result is :" + sb.toString());
			return sb.toString();
		}
		try {
			daoService.getKCFA(lines);
			sb.append("0::success::#END");
		} catch (Exception e) {
			sb.append("-1::").append(e.getMessage()).append(" all rollbacked::#END");
		}
		log.info("return getKCFA msg is :" + sb.toString());
		return sb.toString();
	}
	
	@Override
	public String getTYLXXZB(String parm) {
		log.info("getTYLXXZB receive msg is :" + parm);
		StringBuffer sb = new StringBuffer("#MSG::");
		String lines = this.getParm(parm);
		if(lines==null || "".equals(lines)){
			sb.append("-1::no rows or error rows::#END");
			log.info("getTYLXXZB result is :" + sb.toString());
			return sb.toString();
		}
		try {
			daoService.getTYLXXZB(lines);
			sb.append("0::success::#END");
		} catch (Exception e) {
			sb.append("-1::").append(e.getMessage()).append(" all rollbacked::#END");
		}
		log.info("return getTYLXXZB msg is :" + sb.toString());
		return sb.toString();
	}
	
	@Override
	public String getTSRYYB(String parm) {
		log.info("getTSRYYB receive msg is :" + parm);
		StringBuffer sb = new StringBuffer("#MSG::");
		String lines = this.getParm(parm);
		if(lines==null || "".equals(lines)){
			sb.append("-1::no rows or error rows::#END");
			log.info("getTYLXXZB result is :" + sb.toString());
			return sb.toString();
		}
		try {
			daoService.getTSRYYB(lines);
			sb.append("0::success::#END");
		} catch (Exception e) {
			sb.append("-1::").append(e.getMessage()).append(" all rollbacked::#END");
		}
		log.info("return getTYLXXZB msg is :" + sb.toString());
		return sb.toString();
	}


	@Override
	public String getGKXX(String parm) {
		log.info("getGKXX receive msg is :" + parm);
		StringBuffer sb = new StringBuffer("#MSG::");
		String lines = this.getParm(parm);
		if(lines==null || "".equals(lines)){
			sb.append("-1::no rows or error rows::#END");
			log.info("getTYLXXZB result is :" + sb.toString());
			return sb.toString();
		}
		try {
			String rt = daoService.getGKXX(lines.replace("||", ""));
			if(rt.startsWith("#HEAD")) return rt;
			sb.append(rt).append("::#END");
		} catch (Exception e) {
			sb.append("-1::").append(e.getMessage()).append(" all rollbacked::#END");
		}
		log.info("return GETGKXX msg is :" + sb.toString());
		return sb.toString();
	}


    @Override
    public String getQGKZ(String parm) {
        log.info("getQGKZ receive msg is :" + parm);
        StringBuffer sb = new StringBuffer("#MSG::");
        String lines = this.getParm(parm);
        if(lines==null || "".equals(lines)){
            sb.append("-1::no rows::#END");
            return sb.toString();
        }
        try {
            daoService.getQGKZ(lines);
            sb.append("0::success::#END");
        } catch (Exception e) {
            sb.append("-1::").append(e.getMessage()).append(" all rollbacked::#END");
            e.printStackTrace();
        }
        log.info("return msg is :" + sb.toString());
        return sb.toString();
    }


    @Override
    public String getYDQGBZ(String parm) {
        log.info("getYDQGBZ receive msg is :" + parm);
        StringBuffer sb = new StringBuffer("#MSG::");
        String lines = this.getParm(parm);
        if(lines==null || "".equals(lines)){
            sb.append("-1::no rows::#END");
            return sb.toString();
        }
        try {
            daoService.getYDQGBZ(lines);
            sb.append("0::success::#END");
        } catch (Exception e) {
            sb.append("-1::").append(e.getMessage()).append(" all rollbacked::#END");
            e.printStackTrace();
        }
        log.info("return msg is :" + sb.toString());
        return sb.toString();
    }


    @Override
    public String getWLGKQGKZ(String parm) {
        log.info("getWLGKQGKZ receive msg is :" + parm);
        StringBuffer sb = new StringBuffer("#MSG::");
        String lines = this.getParm(parm);
        if(lines==null || "".equals(lines)){
            sb.append("-1::no rows::#END");
            return sb.toString();
        }
        try {
            daoService.getWLGKQGKZ(lines);
            sb.append("0::success::#END");
        } catch (Exception e) {
            sb.append("-1::").append(e.getMessage()).append(" all rollbacked::#END");
            e.printStackTrace();
        }
        log.info("return msg is :" + sb.toString());
        return sb.toString();
    }
	
    @Override
    public String getJBZLTJBZ(String parm) {
        log.info("getJBZLTJBZ receive msg is :" + parm);
        StringBuffer sb = new StringBuffer("#MSG::");
        String lines = this.getParm(parm);
        if(lines==null || "".equals(lines)){
            sb.append("-1::no rows::#END");
            return sb.toString();
        }
        try {
            daoService.getJBZLTJBZ(lines);
            sb.append("0::success::#END");
        } catch (Exception e) {
            sb.append("-1::").append(e.getMessage()).append(" all rollbacked::#END");
            e.printStackTrace();
        }
        log.info("return msg is :" + sb.toString());
        return sb.toString();
    }
}